package com.bw.controller;

import com.bw.ann.MyAnn;
import com.bw.domain.TBrand;
import com.bw.domain.TGoods;
import com.bw.service.TBrandService;
import com.bw.service.TGoodsService;
import com.bw.utils.common.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author bobo棒
 * @date 2023年10月30日 15:47
 */

@RestController
@RequestMapping("goods")
public class GoodsController {

    @Autowired
    TGoodsService tGoodsService;
    @Autowired
    TBrandService tBrandService;



    @RequestMapping("delById")
    public Result delById(Integer id){
        boolean b = tGoodsService.removeById(id);
        return b?Result.success():Result.fail();
    }


    @MyAnn
    @RequestMapping("list")
    public Result list(@RequestBody TGoods tGoods, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "3") Integer pageSize){

        PageHelper.startPage(current,pageSize);
        List<TGoods> list = tGoodsService.list(tGoods);
        PageInfo<TGoods> info = new PageInfo<>(list);
        //记录日志
        return Result.success(info);
    }

    @RequestMapping("listBrands")
    public Result listBrands(){

        List<TBrand> list = tBrandService.list();
        return Result.success(list);
    }
}
